<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>
    <template v-if="isRegister">
      <el-tabs type="border-card" stretch v-model="currentTab">
        <el-tab-pane name="account">
          <template #label>
            <span><i class="el-icon-user-solid"></i> 账号登录</span>
          </template>
          <LoginAccount ref="accountRef" />
        </el-tab-pane>
        <el-tab-pane name="phone">
          <template #label>
            <span><i class="el-icon-mobile-phone"></i> 手机登录</span>
          </template>
          <LoginPhone ref="phoneRef" />
        </el-tab-pane>
      </el-tabs>
      <div class="account-control">
        <el-checkbox v-model="isKeepPassword">记住密码</el-checkbox>
        <el-link type="primary">忘记密码</el-link>
      </div>
      <el-button
        type="primary"
        ref="loginButton"
        class="login-btn"
        @click="handleLoginClick"
        >立即登录</el-button
      >
      <el-button class="login-btn1" @click="handleRegister">立即注册</el-button>
    </template>
    <template v-else>
      <el-tabs type="border-card" stretch v-model="currentTab">
        <el-tab-pane name="account">
          <template #label>
            <span><i class="el-icon-user-solid"></i> 账号注册</span>
          </template>
          <Register ref="registerRef"></Register>
        </el-tab-pane>
      </el-tabs>

      <span class="font1">注册或登录即同意商家协议，且需完善信息</span>
      <el-button
        type="primary"
        ref="loginButton"
        class="login-btn3"
        @click="handleRegisterIn"
        >立即注册</el-button
      >
    </template>
  </div>
</template>

<script setup lang="ts">
import { log } from 'console'
import { ref } from 'vue'
import LoginAccount from './login-account.vue'
import LoginPhone from './login-phone.vue'
import Register from './register.vue'
// 1.定义属性
const isKeepPassword = ref(true)
const accountRef = ref<InstanceType<typeof LoginAccount>>()
const phoneRef = ref<InstanceType<typeof LoginPhone>>()
const registerRef = ref<InstanceType<typeof Register>>()

const currentTab = ref('account')
const isRegister = ref(true)
// 2.定义方法
const handleLoginClick = () => {
  if (currentTab.value === 'account') {
    accountRef.value?.loginAction(isKeepPassword.value)
  } else {
    console.log('phoneRef调用loginAction')
  }
}
//处理注册逻辑
const handleRegister = () => {
  isRegister.value = !isRegister.value
}
const handleRegisterIn = () => {
  isRegister.value = !isRegister.value
}
</script>

<style scoped lang="less">
.login-panel {
  margin-bottom: 150px;
  width: 320px;

  .title {
    text-align: center;
  }

  .account-control {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
  }

  .login-btn {
    width: 100%;
    margin-top: 10px;
  }
  .login-btn1 {
    width: 100%;
    margin-left: 0px;
    margin-top: 10px;
  }
}
.login-btn3 {
  width: 100%;
  margin-top: 20px;
}
.font1 {
  margin-top: 20px;
  display: inline-block;
  width: 320px;
  font-size: 12px;
  color: rgb(143, 149, 158);
  text-align: center;
}
</style>
